/**
 * Created by duwei on 2019/4/1.
 */
var ZiPai_ZongJieSuanJavaWindow_qylds = ZiPai_ZongJieSuanJavaWindow.extend({
    _ccsFileName :res.ZiPai_ZongJieSuanWindow_qylds_json,
    /**
     * 点击时间
     * @private
     */
    _initClickListeners: function () {
        this._super();
        this._clickListeners = {
            'root.btn_return': '_clickReturn',
            'root.btn_xianliao': '_clickXianliao',
            'root.btn_weixin': '_clickWeixin',
            'root.btn_fenxianglianjie': '_clickFenxianglianjie',
            'root.btn_cpyInfo': '_clickCpyInfo'
        };
    },
    /**
     * 初始化界面
     * @private
     */
    _initInfo: function () {
        var self = this;
        self.fenshu = "";
        self._setRoomId();
        self._setTime();
        self._setPlayers();
        self._setRowPos();
        self._setInfoText();
    },
    /**
     * 设置房间号/局数/玩法描述/钱有权标记
     */
    _setRoomId: function () {
        var self = this;
        this._nodeList["root.txtRoomId"].setString('房号：' + gameData.roomId);
        this._nodeList["root.txtRounds"].setString('局数：' + self._data['cur_round'] + '/' + self._data['total_round']);
        this._nodeList["root.txtRoomInfo"].setString(self.handleWanfaDesp(gameData.wanfaDesp));
        if (self._data.club_id && !isNaN(parseInt(self._data.club_id)) && parseInt(self._data.club_id) > 0){
            this._nodeList['root.flag_qinyouquan'].setVisible(true);
            loadHeadImage(self._data.club_info.club_head, this._nodeList['root.flag_qinyouquan.head'], true);
            this._nodeList['root.flag_qinyouquan.clubName'].setString(self._data.club_info.club_name);
            //this._nodeList['root.flag_qinyouquan.clubID'].setString(self._data.club_id);
        }
        else {
            this._nodeList['root.flag_qinyouquan'].setVisible(false);
        }
    },
    _clickXianliao: function () {

    },

    _clickWeixin: function () {
        var self = this;
        WeChatUtil.shareCapture(self);
    },
    _clickFenxianglianjie: function () {

    },
    /**
     * 玩法描述修改
     * @param wanfaDesp
     * @returns {string}
     */
    handleWanfaDesp: function (wanfaDesp){
        var removedStrArr =['2人PK', '3人激情', '2人玩', '3人玩', '4人玩',
            '局数: 6局', '局数: 8局', '局数: 10局', '群主支付', '房主支付', 'AA支付'];
        var retVal = wanfaDesp;
        var retValArr = retVal.split(',');
        var locationArr = [];
        for (var i = 0; i < retValArr.length; i++){
            retValArr[i] = retValArr[i].trim();
            if (removedStrArr.indexOf(retValArr[i]) > -1) locationArr.push(i);
        }

        for (var i = locationArr.length - 1; i > -1; i--){
            retValArr.splice(locationArr[i], 1);
        }

        retVal = retValArr.join(',');

        return retVal;
    },
    _clickCpyInfo: function () {
        var self = this;
        var clubName = self._data.club_info.club_name == '' ? '' : (self._data.club_info.club_name + '\n');
        var jushu = '(' + self._data.cur_round + '/' + self._data.total_round + ')';
        var jiesuanTitle = ' 总结算 ';
        var roomId = '房间号：' + self._data.room_id + '\n';
        var playerinfo = '';
        for (var i = 0; i < self._data.players.length; i++) {
            var tmpInfo = self._data.players[i];
            var tmpName = gameData.getPlayerInfoByUid(tmpInfo['uid'])['nickname'];
            var score = tmpInfo.score;
            playerinfo += (tmpName + ' : ' + score + '\n');
        }

        var wanfaDesp = gameData.wanfaDesp;

        var cpyInfo = clubName + jushu + jiesuanTitle + roomId + playerinfo + wanfaDesp;
        console.log(cpyInfo);
        DeviceUtil.savePasteBoard(cpyInfo);
        showToast('复制成功');
    }
});